///:Demo6.java
package com.cqgcxy.stranger.case6;

import java.util.ArrayList;

/**
 * @author icechen1219
 * @date 2018/11/20
 */
public class Demo6 {
    private static final int COUNT = 2 * 10000;

    public static void testString() {
        long begin = System.currentTimeMillis();

        String tmp = "";
        for (int i = 0; i < COUNT; i++) {
            tmp += i;
        }

        long end = System.currentTimeMillis();
        System.out.println((end - begin) + " 毫秒");
    }

    public static void testStringBuffer() {
        long begin = System.currentTimeMillis();

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < COUNT; i++) {
            sb.append(i);
        }

        long end = System.currentTimeMillis();
        System.out.println((end - begin) + " 毫秒");
    }

    public static void main(String[] args) {
        testStringBuffer();
        testString();
    }
}
///:Demo6.java
